package org.walkerljl.practice;

import java.util.concurrent.Callable;

/**
 * 任务
 *
 * @author lijunlin
 */
public class Task implements Callable<Integer> {

    private Long id;
    private Integer nonce;

    public Task(Long id, Integer nonce) {
        this.id = id;
        this.nonce = nonce;
    }

    @Override
    public Integer call() throws Exception {
        try  {
            Thread.sleep(nonce * 1000);
            System.out.println(String.format("[%s]Success to cancel", toString()));
            int i = 1 / 0;
            return nonce;
        } catch(InterruptedException e) {
            System.out.println(String.format("[%s]Success to cancel", toString()));
        }
        return null;
    }

    @Override
    public String toString() {
        return "Task{" +
                "id=" + id +
                ", nonce=" + nonce +
                '}';
    }
}
